﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TLang.Values
{
    public class RecordValue : Value
    {
        public String name;
        public RecordType type;
        public Scope properties;


        public RecordValue(String name, RecordType type, Scope properties)
        {
            this.name = name;
            this.type = type;
            this.properties = properties;
        }


        public override String ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(Constants.PAREN_BEGIN);
            sb.Append(Constants.RECORD_KEYWORD).Append(" ");
            sb.Append(name == null ? "_" : name);

            foreach (string field in properties.Keys)
            {
                sb.Append(" ").Append(Constants.SQUARE_BEGIN);
                sb.Append(field).Append(" ");
                sb.Append(properties.LookupLocal(field));
                sb.Append(Constants.SQUARE_END);
            }

            sb.Append(Constants.PAREN_END);

            return sb.ToString();
        }
    }
}
